"""
通知相关的 Pydantic Schema
"""
from pydantic import BaseModel, Field
from typing import Optional
from datetime import datetime


class NotificationBase(BaseModel):
    """通知基础模型"""
    title: str = Field(..., max_length=200, description="通知标题")
    desc: str = Field(..., description="通知描述")
    date: str = Field(..., description="通知日期")
    is_read: Optional[bool] = Field(False, description="是否已读")


class NotificationCreate(NotificationBase):
    """创建通知的请求模型"""
    pass


class NotificationUpdate(BaseModel):
    """更新通知的请求模型"""
    title: Optional[str] = Field(None, max_length=200, description="通知标题")
    desc: Optional[str] = Field(None, description="通知描述")
    date: Optional[str] = Field(None, description="通知日期")
    is_read: Optional[bool] = Field(None, description="是否已读")


class NotificationResponse(NotificationBase):
    """通知响应模型"""
    id: int = Field(..., description="通知ID")
    status: int = Field(..., description="状态")
    created_at: datetime = Field(..., description="创建时间")
    updated_at: datetime = Field(..., description="更新时间")

    class Config:
        from_attributes = True

    def to_flask_format(self):
        """转换为 Flask 格式的响应（_id 字段名）"""
        data = self.model_dump()
        data['_id'] = str(data.pop('id'))
        return data


class NotificationListResponse(BaseModel):
    """通知列表响应模型"""
    notifications: list
    total: int
    totalPages: int
    currentPage: int
    perPage: int

